﻿//初始化表单
function initialServiceInfo() {
    //绑定下拉列表
    bindSelectList();


    var name, value;
    var urlinfo = window.location.href; //获取当前页面的url
    var num = urlinfo.indexOf("?");
    urlinfo = urlinfo.substr(num + 1);
    var action = ""; //页面URL中读取action参数值 
    var arr = urlinfo.split("&");
    for (var i = 0; i < arr.length; i++) {
        num = arr[i].indexOf("=");
        if (num > 0) {
            name = arr[i].substr(0, num);
            value = arr[i].substr(num + 1);
            this[name] = value;
            if (name == "action")
                action = value;
        }
        }

//        var urlinfo = window.location.href; //获取当前页面的url
//        var len = urlinfo.length; //获取url的长度
//        var offset = urlinfo.indexOf("?"); //设置参数字符串开始的位置
//        var newsidinfo = urlinfo.substr(offset, len)//取出参数字符串 这里会获得类似“id=1”这样的字符串
//        var newsids = newsidinfo.split("="); //对获得的参数字符串按照“=”进行分割    // var  xzq=Number(newsids[1]);//得到参数值
//        var action = (newsids[2]); //得到参数值
//        var newsids2 = newsids[1].split("&");
//        var strId = newsids2[0];

    if (action == "edit" || action == "add") {
        $.ajax({
            type: "post",
            async: false,
            url: "/PZ1.ashx",
            data: //发送到服务器的参数
            {
            stype: "getServiceInfo",
//            TID: strId
            TID: strId
        },
        datatype: "json",
        success: function (result) {
            //进行表单文本项值绑定
            var pinfo = JSON.parse(result);
            var fieldText = ["name", "prj", "URL", "orderindex", "nodename", "nodevalue", "position"]; //text id
            var fieldSql = ["NAME", "PRJ", "URL", "ORDERINDEX", "NODENAME", "NODEVALUE", "POSITION"]; //对应的数据库字段ID
            for (var k = 0; k < fieldText.length; k++) {
                $("#" + fieldText[k]).attr("value", pinfo[0][fieldSql[k]]);
            }

            //进行下拉列表选中项设置
            var selectList = ["arrowclassname", "checkclassname", "classname", "iconclassname", "servicetype", "source", "status", "params", "servertype", "style"]; //select ID
            var selectListSql = ["ARROWCLASSNAME", "CHECKCLASSNAME", "CLASSNAME", "ICONCLASSNAME",
                   "SERVICETYPE", "SOURCE", "STATUS", "PARAMS", "SERVERTYPE", "STYLE"]; //对应数据库字段ID
            for (var j = 0; j < selectList.length; j++) {
                $("#" + selectList[j]).val(pinfo[0][selectListSql[j]]);
            }
        }
    });
    }
    if (action == "view") {
        //隐藏提交按钮
        $("#btSubmit").hide();
        //字段不可编辑
//        $("#nodename").attr('readonly', true);
//        $("#nodevalue").attr('readonly', true);
        //        $("#position").attr('readonly', true);
        $("input").attr('readonly', true);
        $("select").attr('readonly', true);

    }
       
}

//提交
function release() {
    var str1 = document.getElementById("name").value;
    var str2 = document.getElementById("prj").value;
    var str3 = document.getElementById("URL").value;
    var str4 = document.getElementById("orderindex").value;
   var str5 = document.getElementById("arrowclassname").value;
    var str6 = document.getElementById("checkclassname").value;
    var str7 = document.getElementById("classname").value;
    var str8 = document.getElementById("iconclassname").value;
    var str9 = document.getElementById("servicetype").value;
    var str10 = document.getElementById("source").value;
    var str11 = document.getElementById("status").value;
    var str12 = document.getElementById("params").value;
    var str13 = document.getElementById("servertype").value;
    var str14 = document.getElementById("style").value;
    var str15 = document.getElementById("nodename").value;
    var str16 = document.getElementById("nodevalue").value;
    var str17 = document.getElementById("position").value;
    var strId = "";
    var action = ""; //页面URL中读取action参数值
   
    var name, value;
    var urlinfo = window.location.href; //获取当前页面的url
    var num = urlinfo.indexOf("?");
    urlinfo = urlinfo.substr(num + 1);
    var arr = urlinfo.split("&");
    for (var i = 0; i < arr.length; i++) {
        num = arr[i].indexOf("=");
        if (num > 0) {
            name = arr[i].substr(0, num);
            value = arr[i].substr(num + 1);
            this[name] = value;
            if (name == "strId")
                strId = value;
                else if (name == "action")
                action = value;
        }
    }


    
    $.ajax({
        type: "post",
        async: false,
        url: "/PZ1.ashx",
        data: //发送到服务器的参数
        {
        str1: str1,
        str2: str2,
        str3: str3,
        str4: str4,
        str5: str5,
        str6: str6,
        str7: str7,
        str8: str8,
        str9: str9,
        str10: str10,
        str11: str11,
        str12: str12,
        str13: str13,
        str14: str14,
        str15: str15,
        str16: str16,
        str17: str17,
       
        stype: "submit",
        action: action,
        TID: strId
    },
    datatype: "json",
    success: function (result) {
        alert(result);

    }
});
}
//绑定下拉列表
function bindSelectOptions(sel, objList) {
    $("#" + sel).empty();
    for (var i = 0; i < objList.length; i++) {
        var obj = objList[i];
        $("#" + sel).append("<option  value='" + obj.TID + "'>" + obj.NAME + "</option>");
    }
}

function bindSelectList() {
    var selectList = ["arrowclassname", "checkclassname", "classname", "iconclassname",
                    "servicetype", "source", "status", "params", "servertype", "style"];
    var selectTypeList = ["图层伸缩标识样式", "图层勾选框样式", "图层内容样式", "图层标识样式",
    "服务种类", "数据源", "服务状态", "参数","服务类型","服务样式"];
    for (var i = 0; i < selectTypeList.length; i++) {
        var selectType = selectTypeList[i];
        var selectName = selectList[i];
        $.ajax({
            type: "post",
            async: false,
            url: "/PZ1.ashx",

            data: //发送到服务器的参数
            {
                stype: "getSubjectList",
                subtype: selectType
            },
            datatype: "json",
            success: function (result) {
                if (result) {
                    var objlist = JSON.parse(result);
                    bindSelectOptions(selectName, objlist);
                }
            },
            error: function (errorMsg) {
                // alert("请求数据失败");
            }
        });
    }  
 }